package com.contain2.queue;

import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.PriorityBlockingQueue;

import com.generic.genericinterface.demo1.Generator;

/**
 * Queue接口有2个实现：LinkedList和PriorityQueue，它们的区别在于排序行为而非性能
 * 
 * @author Administrator
 *
 */
public class QueueBehavior {

	private static int count = 10;

	static <T> void test(Queue<T> queue, Generator<T> gen) {
		for (int i = 0; i < count; i++) {
			queue.offer(gen.next());
		}
		System.out.println(queue);
		while (queue.peek() != null) {
			System.out.print(queue.remove() + " ");
		}
		System.out.println("");
	}

	static class Gen implements Generator<String> {
		String[] s = ("one two three four five six seven eight nine ten")
				.split(" ");
		int i;

		public String next() {
			return s[i++];
		}
	}

	public static void main(String[] args) {
		test(new LinkedList<String>(), new Gen());
		test(new ArrayBlockingQueue<String>(count), new Gen());
		test(new ConcurrentLinkedQueue<String>(), new Gen());
		test(new PriorityQueue<String>(), new Gen());
		test(new PriorityBlockingQueue<String>(), new Gen());
	}

}
